﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KylinORM.CQRS
{
    /// <summary>
    /// 注册消息响应
    /// </summary>
    [Serializable]
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
    public class OnMessageAttribute : Attribute
    {
        /// <summary>
        /// 定义当前方法为消息的响应
        /// </summary>
        /// <param name="messageName">要处理的消息名称</param>
        /// <param name="endpointUrl">消息端点地址，MessageBus.CommandServiceUrl或MessageBus.EventServiceUrl</param>
        public OnMessageAttribute(string messageName, string endpointUrl)
        {
            this.MessageName = messageName;
            this.EndpointUrl = new Uri(endpointUrl);
        }
        /// <summary>
        /// 定义当前方法为消息的响应
        /// </summary>
        /// <param name="messageName">要处理的消息名称</param>
        /// <param name="endpointUrl">消息端点地址，MessageBus.CommandServiceUrl或MessageBus.EventServiceUrl</param>
        /// <param name="messageType">消息响应的类型</param>
        public OnMessageAttribute(string messageName, string endpointUrl, EMessageType messageType)
        {
            this.MessageName = messageName;
            this.EndpointUrl = new Uri(endpointUrl);
            this.MessageType = messageType;
        }

        /// <summary>
        /// 要处理的消息名称
        /// </summary>
        public string MessageName { get; set; }
        /// <summary>
        /// 消息端点地址，格式object://命名空间/类名/属性名
        /// </summary>
        public Uri EndpointUrl { get; set; }
        /// <summary>
        /// 消息响应的类型，值为NULL时使用消息类型
        /// </summary>
        public EMessageType? MessageType { get; set; }
    }
}
